﻿@model List<SysUser>
@{
	ViewBag.Title = "Danh sách người dùng";
}

<div class="main-content-inner">
	<div class="breadcrumbs" id="breadcrumbs">
		<ul class="breadcrumb">
			<li>
				<i class="ace-icon fa fa-home home-icon"></i>
				<a href="#">Home</a>
			</li>
			<li><a href="@Url.Action("Index")">Dashboard</a></li>
			<li class="active">Danh sách người dùng</li>
		</ul>
		<!-- /.breadcrumb -->


		<!-- /.nav-search -->
	</div>

	<div class="page-content">


		<div class="page-header">
			<h1>@ViewBag.Title

			</h1>
		</div>
		<!-- /.page-header -->
		<div class="row">
			<div class="col-xs-12">
				<!-- PAGE CONTENT BEGINS -->
				<div class="row">
					<div class="col-xs-12">
						@using (Html.BeginForm(null, null, FormMethod.Post, new { @id = "manageForm" }))
	  {
							@Html.AntiForgeryToken()
							
							<table id="dynamic-table" class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th>Tên đăng nhập</th>
										<th>Họ tên</th>
										<th>SysAdmin</th>
										<th>Status</th>
										<th></th>
									</tr>
								</thead>

								<tbody>
									@if (Model != null && Model.Count > 0)
		 {
			 foreach (var item in Model)
			 {
										<tr>

											<td>
												@item.Username
											</td>
											<td>@item.Fullname</td>


											<th>
												@if (item.SysAdmin)
			{
													<span class="label label-sm label-success">SysAdmin</span>
			}
			else
			{
													<span class="label label-sm label-danger">Normal</span>
			}
											</th>

											<th>
												@if (item.Active)
			{
													<span class="label label-sm label-success">Active</span>
			}
			else
			{
													<span class="label label-sm label-danger">Inactive</span>
			}
											</th>
											<td>
												<div class="hidden-sm hidden-xs btn-group">

													<a class="btn btn-xs btn-info" href="@Url.Action("UserEdit", "User", new { Id = item.Username })" >
														<i class="ace-icon fa fa-pencil bigger-120"></i>
													</a>

													<a class="btn btn-xs btn-info" href="@Url.Action("ResetPassword","User")" data-toggle="modal" data-target="#ChangePassModal" data-username="@item.Username">
																<i class="ace-icon fa fa-sign-in bigger-120"></i>
													</a>

													<a href="javascript:" class="btn btn-xs btn-danger" onclick="DeleteUser('@item.Username','@item.Username')">

														<i class="ace-icon fa fa-trash-o bigger-120"></i>
													</a>


												</div>


											</td>
										</tr>
			 }
		 }

								</tbody>
							</table>
	  }
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<a href="@Url.Action("UserCreate")" class="btn btn-success">Tạo mới</a>
					</div>
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
	</div>
	<!-- /.page-content -->
</div>


<div class="modal fade" id="ChangePassModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">Reset password</h4>
      </div>
      <div class="modal-body">
        <form action="@Url.Action("ResetPassword","User")" method="post">
            <input type="hidden" id="userName" name="userName" />
          <div class="form-group">
            <label for="password" class="control-label">Password:</label>
            <input type="text" class="form-control" name="password" id="password" required>
          </div>
          
        <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary" id="btnSave">Save</button>
      </div>
        </form>
      </div>
      
    </div>
  </div>
</div>

<script type="text/javascript">
	jQuery(function ($) {
		//initiate dataTables plugin
		var oTable1 =
        $('#dynamic-table')
        //.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
        .dataTable({
        	bAutoWidth: false,
        	"aoColumns": [
					  null, null, null, null,
					  { "bSortable": false }
        	],
        	"aaSorting": [],

        	//,
        	//"sScrollY": "200px",
        	//"bPaginate": false,

        	//"sScrollX": "100%",
        	//"sScrollXInner": "120%",
        	//"bScrollCollapse": true,
        	//Note: if you are applying horizontal scrolling (sScrollX) on a ".table-bordered"
        	//you may want to wrap the table inside a "div.dataTables_borderWrap" element

        	//"iDisplayLength": 50
        });
		//oTable1.fnAdjustColumnSizing();



		/********************************/
		//add tooltip for small view action buttons in dropdown menu
		$('[data-rel="tooltip"]').tooltip({ placement: tooltip_placement });

		//tooltip placement on right or left
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table')
			var off1 = $parent.offset();
			var w1 = $parent.width();

			var off2 = $source.offset();
			//var w2 = $source.width();

			if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
			return 'left';
		}

		$('#ChangePassModal').on('show.bs.modal', function (event) {
			var button = $(event.relatedTarget) // Button that triggered the modal
			var recipient = button.data('username') // Extract info from data-* attributes
			// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
			// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
			var modal = $(this)
			modal.find('.modal-title').text('ResetPassword for ' + recipient)
			modal.find('#userName').val(recipient)
		});

	});
	function DeleteUser(id, title) {
		bootbox.confirm("Xóa thông tin người dùng " + title , function (result) {
			if (result) {
				
			}
		});
	}
</script>

<script type="text/javascript">
	setAdminCurrentUrl('@Url.Action("Index", "User")');
</script>
